//<script language=javascript>
// Ultimate client-side JavaScript client sniff. 
// Portions (C) Netscape Communications 1999.  Reused and redistributed with
// permission.
//
// Portions (C) Outtask.com, Inc. 2000.  May be reused and redistributed.
//
// Functional comments removed to reduce payload (sorry Netscape)

function BrowserCheck ()
{   // convert all characters to lowercase to simplify testing 
    var agt=navigator.userAgent.toLowerCase(); 
	var msie_vers_start = agt.indexOf("msie")+5;
	var msie_real_vers = parseFloat(agt.substring(msie_vers_start, msie_vers_start+3));    

    // *** BROWSER VERSION *** 
    // Note: On IE5, these return 4, so use is.ie5up to detect IE5. 
    this.major = parseInt(navigator.appVersion); 
    this.minor = parseFloat(navigator.appVersion); 

    this.nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) 
                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) 
                && (agt.indexOf('webtv')==-1)); 
    this.nav2 = (this.nav && (this.major == 2)); 
    this.nav3 = (this.nav && (this.major == 3)); 
    this.nav4 = (this.nav && (this.major == 4)); 
    this.nav4up = (this.nav && (this.major >= 4)); 
    this.navonly      = (this.nav && ((agt.indexOf(";nav") != -1) || 
                          (agt.indexOf("; nav") != -1)) ); 

	this.nav7 = (this.nav && (agt.indexOf('netscape/7') != -1));
	//this.nav7up = ???
    
	this.nav6 = (this.nav && (agt.indexOf('netscape6') != -1));
	this.nav6up = (this.nav && document.getElementById) ? true : false ;  
    
    this.nav5 = (this.nav && (this.major == 5) && (!this.nav7 && !this.nav6) ); 
    this.nav5up = (this.nav && (this.major >= 5)); 
	
    this.ie   = (agt.indexOf("msie") != -1); 
    this.ie3  = (this.ie && (this.major < 4)); 
    
    this.ie4  = (this.ie && (this.major == 4) && (msie_real_vers < 5));
    this.ie4up  = (this.ie  && (this.major >= 4));
    this.ie5  = (this.ie && (this.major == 4) && (agt.indexOf("msie 5.")!=-1));
    this.ie5up  = (this.ie  && !this.ie3 && !this.ie4);
    
    this.ie55up = (this.ie5up && window.createPopup)?true:false;
    this.ie6 = (this.ie && (agt.indexOf("msie 6.") > 0));
    this.ie6up = (this.ie && !this.ie3 && !this.ie4 && !this.ie5);   
    this.ie7 = (this.ie && (agt.indexOf("msie 7.") > 0));
	this.ie7up  = (this.ie  && window.XMLHttpRequest);


    this.gecko = (agt.indexOf("gecko") != -1); 
    this.opera = (agt.indexOf("opera") != -1); 
    this.webtv = (agt.indexOf("webtv") != -1); 
    this.safari = (agt.indexOf("safari") != -1);
    
    this.mozilla = this.gecko && (agt.indexOf("netscape") == -1);
    this.firefox = this.mozilla && (agt.indexOf("firefox/") > 0);
    this.firefox2 = this.firefox && (agt.indexOf("firefox/2.") > 0);
    this.chrome = this.mozilla && (agt.indexOf("chrome/") > 0);
    
    // *** PLATFORM *** 
    this.win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) ); 
    // NOTE: On Opera 3.0, the userAgent string includes "Windows 95/NT4" on all 
    //        Win32, so you can't distinguish between Win95 and WinNT. 
    this.win95 = ((agt.indexOf("win95")!=-1) || (agt.indexOf("windows 95")!=-1)); 

    this.win31 = ((agt.indexOf("windows 3.1")!=-1) || (agt.indexOf("win16")!=-1) || 
                  (agt.indexOf("windows 16-bit")!=-1)); 
                  
} 


// It is up to the calling page to handle nested layers in Netscape 4
// So parentObj can be empty or 'document.div1' or 'document.div3.document.div2.document.div1'
function getNamedObj(name, parentObj)
{
    if((typeof(parentObj)=='undefined') || (this.ie5up || this.nav6up)) parentObj = 'document';
    var foundObj;
    var getObjCmd = parentObj + ".";
    if (this.ie5up || this.nav6up)
    {
		foundObj = eval(parentObj + ".getElementById(\'" + name + "\')");
		if (foundObj == null || foundObj == "undefined" || !foundObj)
		{
			foundObj = eval(parentObj + ".getElementsByName(\'" + name + "\')[0]");
		}
		return foundObj;
    }
    else if ( this.ie4up )
	{
	    getObjCmd += 'all.';
	}
	getObjCmd += name;
	
	foundObj = eval("getObjCmd");
	
    return foundObj;
}

function insertInto(name, theHTML)
{
	var theObj = this.getNamedObj(name);
	
	if (theObj != null)
	{
		if ( theObj.innerHTML != null)
		{
			theObj.innerHTML = theHTML;
		}
		else
		{
			with (theObj.document) {
				open();
				write(theHTML);
				close();
			}
		}
	}
}

function getOffsetLeft (theObj, includeScroll) {
	var ol = theObj.offsetLeft;
	if (includeScroll)
	{
		ol -= theObj.scrollLeft;
		ol += (document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;
	}
	
	while ((theObj = theObj.offsetParent) != null)
	{
		ol += theObj.offsetLeft;
		if (includeScroll)
			ol -= theObj.scrollLeft;
	}
	
  return ol;
}

function getOffsetTop (theObj, includeScroll) {
	var ot = theObj.offsetTop;
	if (includeScroll)
	{
		ot -= theObj.scrollTop;
		ot -= (document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
	}
		
	while((theObj = theObj.offsetParent) != null)
	{
		ot += theObj.offsetTop;
		if (includeScroll)
			ot -= theObj.scrollTop;
	}
  return ot;
}

function findParentByTagName(element, tagName)
{
	while (element.parentNode && (!element.tagName || (element.tagName.toUpperCase() != tagName.toUpperCase()))) {
			element = element.parentNode;
	}
	return (element.tagName && element.tagName.toUpperCase() == tagName.toUpperCase()) ? element : null;
}

function getObjX(theObj)
{
    // window object
    if (theObj.history)
    {
		if (this.ie4up) return theObj.screenLeft;
		if (this.navup) return theObj.screenX;
	}
    // image object
    else if (theObj.src)
    {
        if ( this.ie4up  || !this.nav6up)
            return;
        else if ( this.nav4 || this.nav6up)
			return theObj.x;
    }
    // positionable element
    else
    {
        if ( this.ie4up  || this.nav6up)
            return getOffsetLeft(theObj);
        else if ( this.nav4 )
            return theObj.pageX;
    }
}

function getObjY(theObj)
{
    // window object
    if (theObj.history)
    {
		if (this.ie4up) return theObj.screenTop;
		if (this.nav) return theObj.screenY;
	}
    // image object
    else if (theObj.src)
    {
        if ( this.ie4up  || !this.nav6up)
            return;
        else if ( this.nav4 || this.nav6up)
			return theObj.y;
    }
    // positionable element
    else
    {
        if ( this.ie4up  || this.nav6up)
            return getOffsetTop(theObj);
        else if ( this.nav4 )
            return theObj.pageY;
    }
}	

function moveObjBy(theObj, deltaX, deltaY)
{
    // This is not as short as it could be, but clearer about separating
    // browser identification from capability identification.
    
    // Netscape 4
    if ( this.nav4)
    {
		theObj.moveBy(deltaX, deltaY);
    }
    // IE4+ positionable object
    else if ( this.ie4up  || this.nav6up)
    {
        // Windows use moveTo
        if ( theObj.history )
        {
            theObj.moveBy(deltaX, deltaY);
        }
        // Other positionable objects use styles
        else
        {
            theObj.style.left += deltaX;
            theObj.style.top += deltaY;
        }
    }
}

function moveObjTo(theObj, left, top)
{
    // This is not as short as it could be, but clearer about separating
    // browser identification from capability identification.

    // Netscape 4
    if ( this.nav4)
    {
		theObj.moveTo(left, top);
    }
    // IE4+ positionable object
    else if ( this.ie4up  || this.nav6up)
    {
        // Windows use moveTo
        if ( theObj.history )
        {
            theObj.moveTo(left, top);
        }
        // Other positionable objects use styles
        else
        {
            theObj.style.left = left;
            theObj.style.top = top;
        }
    }
}




function widthOf (theObj)
{
    var objWidth;

    // screen object
    if (theObj.availWidth)
    {
        return theObj.availWidth;
    }
    // window object
    else if (theObj.history)
    {
		if (window.innerHeight) {
			// netscape
			objWidth = theObj.innerWidth;
		}   
		else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
			// ie6 strict
			objWidth = theObj.document.documentElement.clientWidth;
		}
		else {
			//if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
			// DOM and IE5
			objWidth = theObj.document.body.clientWidth;
		}
	}
    // positionable element
    else
    {
        if (this.ie4up  || this.nav6up)
            objWidth = theObj.offsetWidth;
        else if ( this.nav4 )
            objWidth = theObj.clip.width;
    }

    return (objWidth);
}

function heightOf (theObj)
{
    var objHeight;
    // screen object
    if (theObj.availHeight)
    {
        objHeight = theObj.availHeight;
    }
    // window object
    else if (theObj.history)
    {
		if (window.innerHeight) {
			// netscape
			objHeight = theObj.innerHeight;
		}   
		else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
			// ie6 strict
			objHeight = theObj.document.documentElement.clientHeight;
		}
		else {
			//if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
			// DOM and IE5
			objHeight = theObj.document.body.clientHeight;
		}
	}
    // positionable element
    else
    {
        if ( this.ie4up  || this.nav6up)
            objHeight = theObj.offsetHeight;
        else if ( this.nav4 )
            objHeight = theObj.clip.height;
    }

    return (objHeight);
}

function centerObj(theObj)
{
	var sWidth = this.widthOf(screen) //getScreenWidth()
	var sHeight = this.heightOf(screen) //getScreenHeight()
	var oWidth = this.widthOf(theObj)
	var oHeight = this.heightOf(theObj)
	
	var oWidth = ( oWidth > sWidth)? sWidth : oWidth
	var oHeight = (oHeight > sHeight)? sHeight : oHeight
	var oLeft = (sWidth-oWidth)/2
	var oTop = (sHeight-oHeight)/2 - 40
	
	this.moveObjTo(theObj,oLeft,oTop)
}

// The accuracy of this depends upon determining the accurate width of the object
// Set style property of obj, ie, "style=width:20px;height:20px"
function centerObjInWindow(theObj)
{
	var midX = ((this.widthOf(window)/2) - (this.widthOf(theObj)) /2);
	var midY = Math.abs(((this.heightOf(window)/2) - (this.heightOf(theObj)) /2));
	this.moveObjTo(theObj, midX, midY);
}

function getWinLeft(width)
{
	var oLeft = (bUtil.widthOf(screen) - width) /2;
	return oLeft;
}

function getWinTop(height)
{
	oTop = (bUtil.heightOf(screen) - height) /2;
	return oTop;
}

// Prevent entering text in a field field - only needed for Nav4
function filterMe(e)
{
	if (bUtil.nav4)
	{
		var retVal = routeEvent(e);
		if(retVal == false) return false;
		else return true;
	}
}

// Prevent entering defined characters in a field
// To use on a page, create an arrKeys() with the keycodes you want to filter
// Add code like: document.frmMain.txtPolicyID.onkeypress=bUtil.filterKeys
//
//	FOR NS4 compatibility you also need to have code like:
// 	if (bUtil.nav4)
//	{
//		window.captureEvents(Event.KEYPRESS)
//		onKeyPress=bUtil.filterMe
//	}
// Window-level capture of Keypress (filterKeys) sends event on to filterMe which sends result back to filterKeys

function filterKeys(evt)
{
	var keyMatch = false;
	for (i=0;i<arrKeys.length;i++)
	{
		if (bUtil.ie4up)
		{
			if (window.event.keyCode == arrKeys[i]) keyMatch = true;
		}
		else if(bUtil.nav4up)
		{
			if(evt.which == arrKeys[i]) keyMatch = true;
		}
	}
	if (bUtil.ie4up && keyMatch == true) window.event.returnValue = false;
	if (bUtil.nav6up && keyMatch == true) event.preventDefault();
	if(bUtil.nav4 && keyMatch == true) return false;
	else return true;
}

function otDisable(item, disable, bDeletevalue)
{
	var isCheckBox = (item.type == 'checkbox' || item.type == 'radio');

	if (!disable)
	{
		item.className = "small-black";
		item.readOnly = false;
		item.tabindex = 0;
		item.onfocus = '';
		if (isCheckBox) item.disabled = false;
	}
	else
	{
		if (bDeletevalue)
		{
			if (!isCheckBox) item.value = '';
			if (isCheckBox) item.checked = false;
		}
		item.className = "readonlytextboxsmall";
		item.readOnly = true;
		item.onfocus = function() {item.blur();}
		if (isCheckBox) item.disabled = true;
	}
}

function hideIt(theObj)
{
	var strStyle = (this.nav4) ? "" : ".style";
	eval("theObj" + strStyle + ".visibility = 'hidden'");
}

function showIt(theObj)
{
	var strStyle = (this.nav4) ? "" : ".style";
	eval("theObj" + strStyle + ".visibility = 'visible'");
}



function toggleVis(theObj)								// For this to work in Netscape 4, the object MUST be a positionable element
{														// So an image or text MUST be surrounded by a div with an inline 
	var strStyle = (this.nav4) ? "" : ".style";			// or style-referenced position
	var isVisible;
	isVisible = eval("theObj" + strStyle + ".visibility");
	
	if (isVisible == null || isVisible == "undefined" || isVisible == "hidden" || isVisible == "hide")
	{
		this.showIt(theObj);
	}
	else
	{
		this.hideIt(theObj)
	}
	
}

function getMouseClickX(e)
{
	if (this.ie) return window.event.offsetX;
	else return e.layerX;
	
}

function getMouseClickY(e)
{
	if (this.ie) return window.event.offsetY;
	else return e.layerY;
}

// checks if point is inside bounding box of elem
function ot_isPointInsideElement(elem,x,y) {

	if (typeof(elem) == "undefined" || elem == null) {
		return false;	
	}

	var elemLeft = this.getOffsetLeft(elem);
	var elemRight = elemLeft + this.widthOf(elem);
	var elemTop = this.getOffsetTop(elem);
	var elemBottom = elemTop + this.heightOf(elem);
	
	// x between left and right boundries, y between top and bottom boundries
	if ((elemLeft <= x && x <= elemRight) && (elemTop <= y && y <= elemBottom)) {
		return true;
	}

	return false;
}

function ot_getElementForPoint(x,y) {

	// if the browser (IE) supports document.elementFromPoint, use that
	if (document.elementFromPoint) {
		return document.elementFromPoint(x,y);
	}
	else {

		// search all elements!
		var elementsList = document.getElementsByTagName("*");
		var elem;
		for (var i = elementsList.length - 1; i >= 0; i--) {
			elem = elementsList[i];

			if (!elem) {
				continue;
			}
			
			// ignore certain elements
			if(elem.tagName == "HTML" || elem.tagName == "BODY" || elem.tagName == "!") {
				continue;
			}
			
			if (this.isPointInsideElement(elem,x,y)) {
				return elem;	
			}
						
		}
		
		return null;

	}
		
}


//
// returns which button was pressed, using the ie standard
//
// 
//
// be careful... ns7 (and presumable mozilla) do not set the button values on mouseMove events, only mouseUp and mouseDown
function ot_getButtonPressed(evt) {

	var buttonPressed = evt.button;
	
	// some older browsers only use the which property... this may or may not work
	if( typeof(buttonPressed) != 'number' || Number(evt.which) > 3) {				
    	buttonPressed = evt.which;
    }

	// convert to ie 
	if (this.gecko) {
        switch (buttonPressed) {
        
        case 0:
        	// left button
        	buttonPressed = 1;
        	break;

        case 1:
        	// middle button
        	buttonPressed = 4;
        	break;

        case 2:
        	// right button
        	buttonPressed = 2;
        	break;

		}
	}

	return buttonPressed;	
}

BrowserCheck.prototype.insertInto = insertInto;
BrowserCheck.prototype.moveObjTo = moveObjTo;
BrowserCheck.prototype.moveObjBy = moveObjBy;
BrowserCheck.prototype.getNamedObj = getNamedObj;
BrowserCheck.prototype.widthOf = widthOf;
BrowserCheck.prototype.heightOf = heightOf;
BrowserCheck.prototype.centerObj = centerObj;
BrowserCheck.prototype.getWinLeft = getWinLeft;
BrowserCheck.prototype.getWinTop = getWinTop;
BrowserCheck.prototype.filterKeys = filterKeys;
BrowserCheck.prototype.filterMe = filterMe;
BrowserCheck.prototype.otDisable = otDisable;
BrowserCheck.prototype.toggleVis = toggleVis;
BrowserCheck.prototype.centerObjInWindow = centerObjInWindow;
BrowserCheck.prototype.hideIt = hideIt;
BrowserCheck.prototype.showIt = showIt;
BrowserCheck.prototype.getObjX = getObjX;
BrowserCheck.prototype.getObjY = getObjY;
BrowserCheck.prototype.getOffsetTop = getOffsetTop;
BrowserCheck.prototype.getOffsetLeft = getOffsetLeft;
BrowserCheck.prototype.getMouseClickX = getMouseClickX;
BrowserCheck.prototype.getMouseClickY = getMouseClickY;
BrowserCheck.prototype.isPointInsideElement = ot_isPointInsideElement;
BrowserCheck.prototype.getElementForPoint = ot_getElementForPoint;
BrowserCheck.prototype.getButtonPressed = ot_getButtonPressed;
BrowserCheck.prototype.findParentByTagName = findParentByTagName;
var bUtil; 

bUtil = new BrowserCheck(); 

